//
//  MVViewController.m
//  LOLVideoPlayer
//
//  Created by SXW on 16/3/28.
//  Copyright © 2016年 盛宣伟. All rights reserved.
//

#import "MVViewController.h"

@interface MVViewController ()

@end

@implementation MVViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //播放视频
    [self playVideo:self.vedioToUrl];
}

#pragma mark - 播放视频

- (void)playVideo:(NSString *)playUrl{
    self.MVPlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:self.vedioToUrl]];
    self.MVPlayer.moviePlayer.shouldAutoplay = YES;
    
    [self.MVPlayer.moviePlayer prepareToPlay];
    [self.MVPlayer.moviePlayer play];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playEnd:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [self presentViewController:self.MVPlayer animated:YES completion:nil];
}

-(void)playEnd:(NSNotification *)notify{
    NSInteger reason = [[[notify userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
    switch (reason) {
        case 1:
            NSLog(@"正常结束");
            break;
        case 2:
            NSLog(@"用户退出");
            [self.navigationController popViewControllerAnimated:NO];
            break;
        default:
            NSLog(@"异常退出");
            break;
    }
}

@end
